package com.juc.learn.vector;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.Vector;

/**
 * ClassName:ThreadDemo
 * Package:com.juc.learn.vector
 * Description:
 *
 * @Author:@郭先森
 * @Create:2025/7/27 - 8:57
 * @Version:v1.0
 */
public class ThreadDemo {
    public static void main(String[] args) {
        //创建Vector集合
        List<String> list = new Vector<>();

        //创建多个线程，往集合中加入元素和取出元素
        for (int i = 0; i < 130; i++) {
            new Thread(()->{
                list.add(UUID.randomUUID().toString().substring(0,4));
                System.out.println(list);
            },"线程"+String.valueOf(i)).start();
        }
        //Vector能够解决List的线程安全问题，因为add方法上加了synchronized关键字
    }
}
